package Thread.pool;

import java.util.concurrent.*;

public class threadPool_callable {
    public static void main(String[] args) throws Exception {
        ExecutorService executor = new ThreadPoolExecutor(3,5,6,
                TimeUnit.SECONDS,new ArrayBlockingQueue<>(5),Executors.defaultThreadFactory()
                ,new ThreadPoolExecutor.AbortPolicy());//创建线程池
        Future<String> submit1 = executor.submit(new MyCallable(100));
        System.out.println(submit1.get());
    }
}
class MyCallable implements Callable<String>{
    int x;
    public MyCallable(int x) {
        this.x=x;
    }
    @Override
    public String call() throws Exception {
        int sum=0;
        for(int i=1;i<=x;i++){
            sum+=i;
        }
        return Thread.currentThread().getName()+"执行结果为:"+sum;
    }

}
